import { View } from "../../../mvc/core/View";
import { IClean } from "../../../../com/gengine/core/IClean";
import { ArrayList } from "../../../common/global/ArrayList";
import { LayerManager } from "../../manager/LayerManager";
import { ObjCreate } from "../common/ObjCreate";
import { SArenaGroup } from "../../../../Message/Public/SArenaGroup";
import { SPublicMiniPlayer } from "../../../../Message/Public/SPublicMiniPlayer";
import { ArenaTeammateAvatar } from "./ArenaTeammateAvatar";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { Language } from "../../../../extend/language/Language";
import { GButton } from "../../../../com/mui/controls/GButton";
import { TweenMax } from "../../../../com/greensock/TweenMax";
import { Quint } from "../../../../com/greensock/easing/Quint";
import { DisplayUtil } from "../../../common/DisplayUtil";
//class ArenaGroupView
    
    export  class ArenaGroupView extends View implements IClean
    {
        constructor()
        {
            super();
            this._avatarList = new ArrayList();
            this.layer = LayerManager.uiLayer;
            this.x = 0;
            this.y = 140;
            this.init();
            return;
        }

        /* internal  */init(): void
        {
            this._avatarSp = ObjCreate.createSprite();
            this.addChild(this._avatarSp);
            return;
        }

        public updateByArenaGroup(arg1: SArenaGroup): void
        {
            if (arg1 != null) 
            {
                this.updateByPlayerArray(arg1.members);
            }
            else 
            {
                this.clean();
                this.hide();
            }
            return;
        }

        public updateByPlayerArray(arg1: Array<any>): void
        {
            var loc1=null;
            var loc2=null;
            this.removeAvatar(false);
            if (!arg1 || arg1.length == 0) 
            {
                this.hide();
                return;
            }
            this.show();
            var loc3=0;
            while (loc3 < arg1.length) 
            {
                loc1 = arg1[loc3] as SPublicMiniPlayer;
                loc2 = this._avatarList.get(loc3) as ArenaTeammateAvatar;
                if (loc2 != null) 
                {
                    loc2.updateData(loc1);
                }
                else 
                {
                    loc2 = new ArenaTeammateAvatar(loc1);
                }
                loc2.y = loc3 * 96;
                if (!this._avatarList.contains(loc2)) 
                {
                    this._avatarList.add(loc2);
                }
                this._avatarSp.addChild(loc2);
                ++loc3;
            }
            if (arg1.length < 1) 
            {
                if (this._teamShowButton && this._teamShowButton.parent) 
                {
                    this.removeChild(this._teamShowButton);
                }
            }
            else if (this._teamShowButton && this._teamShowButton.parent == null) 
            {
                this.addChild(this._teamShowButton);
            }
            return;
        }

        public set needShowHideBtn(arg1: Boolean)
        {
            this._teamShowButton = ObjCreate.createGButton("", 0, -13, 21, 20);
            this._teamShowButton.styleName = "PrevPageButton";
            this._teamShowButton.toolTipData = HTMLUtil.addColor(Language.getString(51013), "#FFFFFF");
            this._teamShowButton.addEventListener(flash.events.MouseEvent.CLICK, this.onTeamShowButtonClickHandler);
            return;
        }

        /* internal  */onTeamShowButtonClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=arg1.target as GButton;
            if (loc1.styleName != "PrevPageButton") 
            {
                this.showTeamAvatar(true);
            }
            else 
            {
                this.showTeamAvatar(false);
            }
            return;
        }

        public showTeamAvatar(arg1: Boolean): void
        {
            if (arg1) 
            {
                TweenMax.to(this._avatarSp, 0.2, {"x": 0, "ease": Quint.easeOut});
                this._teamShowButton.width = 21;
                this._teamShowButton.height = 20;
                this._teamShowButton.styleName = "PrevPageButton";
                this._teamShowButton.toolTipData = HTMLUtil.addColor(Language.getString(51013), "#FFFFFF");
            }
            else 
            {
                TweenMax.to(this._avatarSp, 0.2, {"x":-200, "ease": Quint.easeOut});
                this._teamShowButton.width = 27;
                this._teamShowButton.height = 92;
                this._teamShowButton.styleName = "ShowTeamButton";
                this._teamShowButton.toolTipData = HTMLUtil.addColor(Language.getString(51019), "#FFFFFF");
            }
            return;
        }

        /* internal  */removeAvatar(arg1: Boolean): void
        {
            var loc1=null;
            var loc2=0;
            while (loc2 < this._avatarList.size()) 
            {
                loc1 = this._avatarList.get(loc2) as ArenaTeammateAvatar;
                if (loc1) 
                {
                    if (loc1.parent) 
                    {
                        DisplayUtil.removeMe(loc1);
                    }
                    if (arg1) 
                    {
                        loc1.clean();
                    }
                }
                ++loc2;
            }
            return;
        }

        public clean(): void
        {
            this.hide();
            this.removeAvatar(true);
            this._avatarList.clear();
            if (this._teamShowButton) 
            {
                this.showTeamAvatar(true);
            }
            return;
        }

        /* internal */ /* var */_avatarList: ArrayList;

        /* internal */ /* var */_avatarSp: Object /* flash.display.Sprite */;

        /* internal */ /* var */_teamShowButton: GButton;
    }
